<template>
  <a-tree-select
    :allowClear="true"
    :dropdownStyle="{ maxHeight: '220px', overflow: 'auto' }"
    :treeData="orgTreeData"
    v-model="value">
  </a-tree-select>
</template>

<script>
    import {mapState} from 'vuex'
export default {
  name: 'orgInputTree',
  props: {
      orgInstId:'',
      currentUser:{
          isAdmin: false
      }
  },
  data () {
    return {
      orgTreeData: [],
      value: undefined
    }
  },
  methods: {
    reset () {
      this.value = ''
    },
    initOrgByInstId(){
        let params={}
        if(this.currentUser && this.currentUser.admin){
            params.instId = this.orgInstId;
        }else{
            params.instId = this.orgInstId;
            params.parentOrgCode = this.currentUser.orgCode;
        }
        this.$get('admin/upmporg',{
            ...params
        }).then((r) => {
            this.orgTreeData = r.data.rows.children
        })
    }
  },
  mounted () {
      console.log(this.currentUser);
      this.initOrgByInstId();
  },
  watch: {
    value (value) {
      this.$emit('change', value)
    }
  }
}
</script>
